package com.huawei.hms.framework.network.restclient.hwhttp.url;

import com.huawei.hms.framework.common.CheckParamUtils;
import com.huawei.hms.framework.network.util.HttpUtils;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class HttpUrl {
    private MalformedURLException exception;
    private List<String> ips = new ArrayList();
    private String strUrl;
    private URL url;

    public HttpUrl(String str) {
        setUrl(str);
    }

    public String getUrl() {
        return this.strUrl;
    }

    public HttpUrl setUrl(String str) {
        CheckParamUtils.checkNotNull(str, "url == null");
        if (HttpUtils.isHttpOrGrsUrl(str)) {
            this.strUrl = str;
            if (HttpUtils.isHttpUrl(this.strUrl)) {
                try {
                    this.url = new URL(str);
                } catch (MalformedURLException e) {
                    this.exception = e;
                }
            }
            return this;
        }
        throw new IllegalArgumentException("url not valid must be http://;https://;grs://");
    }

    public URL getURL() throws MalformedURLException {
        if (this.url != null) {
            return this.url;
        }
        throw this.exception;
    }

    public String getHost() {
        return this.url == null ? "" : this.url.getHost();
    }

    public List<String> getIps() {
        return this.ips;
    }

    public HttpUrl setIps(List<String> list) {
        this.ips = list;
        return this;
    }

    public HttpUrl addIp(String str) {
        this.ips.add(str);
        return this;
    }

    public int getPort() {
        return this.url == null ? -1 : this.url.getPort();
    }

    public String toString() {
        return super.toString();
    }
}
